package com.adinnet.api.contact.controller;


import com.adinnet.api.common.model.AuthUtil;
import com.adinnet.api.contact.model.ContactReq;
import com.adinnet.api.contact.service.ContactService;
import com.adinnet.api.user.model.User;
import com.adinnet.core.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 联系我们（意见反馈） 前端控制器
 * </p>
 *
 * @author zYshuai
 * @since 2020-12-04
 */
@RestController
@RequestMapping("/api/contact")
public class ContactController {


    @Autowired
    private ContactService contactService;

    /**
     * 用户提交意见
     *
     * @param contact
     * @return
     */
    @ResponseBody
    @PostMapping("/create")
    public JsonResult createContact(@Valid @RequestBody ContactReq contact) {
        try {

            User loginUser = AuthUtil.getLoginUser();
            if (null == loginUser) {
                return JsonResult.error(401,"请您先登录!");
            }
            contactService.createContact(contact);
            return JsonResult.ok("感谢您提供的宝贵意见，帮助豆豆藤不断成长！");
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error("反馈失败!");
        }
    }
}
